//
//  MoreCommentViewController.m
//  BTRIP
//
//  Created by johnbk on 15/11/14.
//  Copyright © 2015年 johnbk. All rights reserved.
//

#import "MoreCommentViewController.h"
#import "DetailGoodShopCommentTableViewCell.h"
#import "Comments.h"
#import "SuitableHeight.h"
@interface MoreCommentViewController ()<UITableViewDataSource, UITableViewDelegate>

@end

@implementation MoreCommentViewController
-(void)dealloc{
	[_tableView release];
	[_naviView release];
	[_buttonOfReturn release];
	[_detailGoodModel release];
	[super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
	self.view.backgroundColor = [UIColor whiteColor];
	[self createTableView];
	[self createNaviView];
}
- (void)createTableView{
	self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
	[self.view addSubview:self.tableView];
	self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
	[self.tableView release];
	self.tableView.delegate = self;
	self.tableView.dataSource = self;
	
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	DetailGoodShopCommentTableViewCell *cell = [DetailGoodShopCommentTableViewCell tableView:tableView];
	cell.comments = self.detailGoodModel.comments[indexPath.row];
	return cell;
	
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
	return self.detailGoodModel.comments.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
	return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
	Comments *comments = self.detailGoodModel.comments[indexPath.row];
	return [SuitableHeight suitableHeight:comments.content andWidth:(self.view.frame.size.width - 40) andFont:12] + 75;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)createNaviView{
	self.naviView = [[UIView alloc]initWithFrame:CGRectMake(0, -20, self.view.frame.size.width, 84)];
	[self.view addSubview:self.naviView];
	[self.naviView release];
	self.naviView.alpha = 0;
	
	self.buttonOfReturn = [UIButton buttonWithType:UIButtonTypeCustom];
	self.buttonOfReturn.frame = CGRectMake(20, 35, 20, 20);
	[self.buttonOfReturn addTarget:self action:@selector(backToFront:) forControlEvents:UIControlEventTouchUpInside];
	[self.buttonOfReturn setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhui-4"] forState:UIControlStateNormal];
	[self.view addSubview:self.buttonOfReturn];
	
	
	
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
	
	
	if (scrollView.contentOffset.y < 0) {
		
		[self.buttonOfReturn setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhui-4"] forState:UIControlStateNormal];
		self.naviView.alpha = 0;
	}
	else if (scrollView.contentOffset.y > 0 && scrollView.contentOffset.y < 64) {
		self.naviView.alpha = scrollView.contentOffset.y / 64;
		
		[self.buttonOfReturn setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhui-3"] forState:UIControlStateNormal];
		
	}
	else{
		self.naviView.backgroundColor = [UIColor whiteColor];
		self.naviView.alpha = 1;
		
		[self.buttonOfReturn setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhui-3"] forState:UIControlStateNormal];
		
	}
	
	
	
}
- (void)backToFront: (UIButton *)button{
	[self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
	[self.navigationController.navigationBar setHidden:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
